﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace Rabbit.API
{
    /// <summary>
    /// 全局异常过滤器
    /// </summary>
    public class AllFilters:IExceptionFilter
    {
        ILogger<AllFilters> log;

        public AllFilters(ILogger<AllFilters> log)
        {
            this.log = log;
        }

        public void OnException(ExceptionContext context)
        {
            try
            {
                log.LogError($"发生全局异常:{context.Exception.Message}");  //记录全局异常
                context.ExceptionHandled = true;  //修改全局异常状态
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
